package com.boomsecret.pattern.decorator.java;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by wangjinliang on 2018/1/26.
 */
public class LowerCaseInputStream extends FilterInputStream {
    protected LowerCaseInputStream(InputStream in) {
        super(in);
    }

    @Override
    public int read() throws IOException {
        int read = super.read();
        if (read != -1) {
            read = Character.toLowerCase((char) read);
        }
        return read;
    }

    @Override
    public int read(byte[] b, int off, int len) throws IOException {
        int result = super.read(b, off, len);
        for (int index = off; index < off + len; index ++) {
            b[index] = (byte) Character.toLowerCase((char) b[index]);
        }
        return result;
    }
}